package com.android.zhushou.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.android.zhushou.R;
import com.android.zhushou.base.BaseFragment;
import com.android.zhushou.ui.activites.AppLoaderActivity;
import com.android.zhushou.ui.activites.MainActivity;
import com.android.zhushou.ui.activites.SuggestActivity;

/**
 * 个人中心
 */
public class PersonFragment extends BaseFragment {
    private View mRootView;
    private RelativeLayout mBtSuggest, mBtUpdate,  mBtFav;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        MainActivity aty = (MainActivity) getActivity();
        aty.setTitleName("个人中心");
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.fragment_setting, container, false);
            creatViews();
        }
        //缓存的mRootView需要判断是否已经被加过parent， 如果有parent需要从parent删除，要不然会发生这个mRootView已经有parent的错误。
        ViewGroup parent = (ViewGroup) mRootView.getParent();
        if (parent != null) {
            parent.removeView(mRootView);
        }
        return mRootView;

    }

    private void creatViews() {
        mBtSuggest = (RelativeLayout) mRootView.findViewById(R.id.bt_suggest);
        mBtUpdate = (RelativeLayout) mRootView.findViewById(R.id.bt_update);
        mBtFav = (RelativeLayout) mRootView.findViewById(R.id.bt_my_fav);
        mBtFav = (RelativeLayout) mRootView.findViewById(R.id.bt_my_fav);

        BtClickListener clickListener = new BtClickListener();
        mBtSuggest.setOnClickListener(clickListener);
        mBtUpdate.setOnClickListener(clickListener);
        mBtFav.setOnClickListener(clickListener);

    }

    private class BtClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            switch (v.getId()) {
                case R.id.bt_suggest:
                    intent.setClass(getActivity(), SuggestActivity.class);
                    startActivity(intent);
                    break;
                case R.id.bt_update:
                    break;
                case R.id.bt_my_fav:
                    //进入收藏的页面
                    intent.setClass(getActivity(), AppLoaderActivity.class);
                    intent.putExtra(AppLoaderActivity.CONTENT_TYPE_KEY, AppLoaderActivity.LIST_TYPE_FAV_TEST);
                    startActivity(intent);
                    break;
            }
        }
    }
}
